﻿//
// Copyright (C) 2010 Tarmin Rehve <tarmin.rehve@gmail.com>
//
//This file is part of the XDataGridView software library.
//
//    XDataGridView is free software: you can redistribute it and/or modify
//    it under the terms of the GNU Lesser Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    XDataGridView is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Lesser License for more details.
//
//    You should have received a copy of the GNU Lesser Public License
//    along with XDataGridView.  If not, see <http://www.gnu.org/licenses/>.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace XDataGridViewTest
{
    public partial class MainForm : Form
    {
        
        public MainForm()
        {
            InitializeComponent();

            XControls.XDataGridViewRowCursor hCursor1 = new XControls.XDataGridViewRowCursor();
            hCursor1.BackColor = Color.Red;
            hCursor1.ForeColor = Color.Yellow;
            xDataGridView.RowCursors.Add(hCursor1);

            xDataGridView.RowCursors.Add();
            xDataGridView.ColumnCursors.Add();
            xDataGridView.ColumnCursors[0].BackColor = Color.Green;
            xDataGridView.ColumnCursors[0].ForeColor = Color.White;

            defaultContextMenuToolStripButton.Checked = xDataGridView.DefaultHandlingInContextMenuStrip;
            allowInsertToolStripButton.Checked = xDataGridView.AllowUserToInsertRows;
            allowDelToolStripButton.Checked = xDataGridView.AllowUserToDeleteRows;
            allowCopyToolStripButton.Checked = xDataGridView.AllowUserToCopyRows;
            allowAddToolStripButton.Checked = xDataGridView.AllowUserToAddRows;
            timer.Enabled = true;
        }

        private void timer_Tick(object sender, EventArgs e)
        {
        if (xDataGridView.Rows.Count > 0)
            if( startToolStripButton.Checked )
                {
                    if( xDataGridView.RowCursors[0].Position <  (xDataGridView.Rows.Count-1) )
                        xDataGridView.RowCursors[0].Position++;
                    else
                        startToolStripButton.Checked = false;
                }

        if(xDataGridView.Columns.Count > 0 )
            if (startToolStripButton.Checked)
                {
                    if (xDataGridView.ColumnCursors[0].Position < (xDataGridView.Columns.Count - 1))
                        xDataGridView.ColumnCursors[0].Position++;
                    else
                        xDataGridView.ColumnCursors[0].Activated = !xDataGridView.ColumnCursors[0].Activated;
                }
        }

        private void startToolStripButton_Click(object sender, EventArgs e)
        {
            startToolStripButton.Checked = !startToolStripButton.Checked;
        }

        private void allowInsertToolStripButton_Click(object sender, EventArgs e)
        {
            allowInsertToolStripButton.Checked = !allowInsertToolStripButton.Checked;
            xDataGridView.AllowUserToInsertRows = allowInsertToolStripButton.Checked;
        }

        private void defaultContextMenuToolStripButton_Click(object sender, EventArgs e)
        {
            defaultContextMenuToolStripButton.Checked = !defaultContextMenuToolStripButton.Checked;
            xDataGridView.DefaultHandlingInContextMenuStrip = defaultContextMenuToolStripButton.Checked;

            allowInsertToolStripButton.Enabled = defaultContextMenuToolStripButton.Checked;
        }

        private void allowDelToolStripButton_Click(object sender, EventArgs e)
        {
            allowDelToolStripButton.Checked = !allowDelToolStripButton.Checked;
            xDataGridView.AllowUserToDeleteRows = allowDelToolStripButton.Checked;
        }

        private void allowCopyToolStripButton_Click(object sender, EventArgs e)
        {
            allowCopyToolStripButton.Checked = !allowCopyToolStripButton.Checked;
            xDataGridView.AllowUserToCopyRows = allowCopyToolStripButton.Checked;
        }

        private void allowAddToolStripButton_Click(object sender, EventArgs e)
        {
            allowAddToolStripButton.Checked = !allowAddToolStripButton.Checked;
            xDataGridView.AllowUserToAddRows = allowAddToolStripButton.Checked;
        }
    }
}
